package main

import (
	"log"
	"net/http"

	"github.com/googollee/go-socket.io"
)

func main() {
	server, err := socketio.NewServer(nil)
	if err != nil {
		log.Fatal(err)
	}
	e := server.On("connection", func(so socketio.Socket) {
		log.Println("connected")
		e := so.On("disconnection", func() {
			log.Println("on disconnect")
		})
		if nil != e {
			log.Print(e.Error())
		}
	})
	if nil != e {
		log.Print(e.Error())
	}
	e = server.On("error", func(so socketio.Socket, err error) {
		log.Println("error:", err)
	})
	if nil != e {
		log.Print(e.Error())
	}

	http.Handle("/socket.io/", server)
	http.Handle("/", http.FileServer(http.Dir("./asset")))
	log.Println("Serving at localhost:7001...")
	log.Fatal(http.ListenAndServe(":7001", nil))
}
